package dexter.core.unit;

import static org.junit.Assert.assertTrue;

import java.util.Properties;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import dexter.core.client.Client;
import dexter.core.client.LocalClient;
import dexter.core.coord.Coordinator;
import dexter.exception.RemoteTestException;

import dexter.util.PropertiesReader;

public class LocalClientTest {
	
	private Coordinator coord;
	
	private Client localClient;
	private Properties props;
	
	@Before
	public void init() {
		props = PropertiesReader.getDefaultProperties();
		coord = new Coordinator(props);
		String host =  props.getProperty("coord_host");
		int port =  Integer.parseInt(props.getProperty("coord_port"));
	    localClient = new LocalClient(host,port);
	}
	
	@Test
	public void testClientCoord() {
		
		coord.start();
		
		try {Thread.sleep(2000);} catch(Exception e) {}
		
		try {
			localClient.executeTest(props);
		} catch (RemoteTestException e) {
			e.printStackTrace();

			assertTrue(false);
		}
		
        assertTrue(true);
		
	}
	
	@Ignore
	@Test
	public void testClientBadId() {
		
		coord.start();
		
		try {Thread.sleep(2000);} catch(Exception e) {}
		
		try {
			props.setProperty("group", "3333333");
			localClient.executeTest(props);
		} catch (RemoteTestException e) {
			e.printStackTrace();

			assertTrue(true);
		}
		
        assertTrue(true);
		
	}	
}
